<?php
class MainLayout extends TTemplateControl
{
	public $serverPathDownload = "assets/images/";
	
	public function onInit($param)
    {
		//echo "MainLayout";
	}
	
	public function btnSearchClicked($sender,$param)
	{
		$str = $this->searchTxt->Text;
		$url = $this->Service->constructUrl('users.Search',array('q' => $str ));
        $this->Response->redirect($url);
	}
	
	/**
     * Logs out a user.
     * This method responds to the "logout" button's OnClick event.
     * @param mixed event sender
     * @param mixed event parameter
     */
    public function logoutButtonClicked($sender,$param)
    {
        $this->Application->getModule('auth')->logout();
        $url=$this->Service->constructUrl($this->Service->DefaultPage);
        $this->Response->redirect($url);
    }
	
	public function getOwnerRecord()
	{
	
	//	$userRecord = UserRecord::finder()->findByEmail($this->user->Email); $this->id
		$userRecord = UserRecord::finder()->findByUser_Id($this->user->ID);
		return $userRecord;
	}
	
	
	public function getAvatar($user)
	{
		if($user->avatarPath == null)
		{
			echo "avatar null";
			if($user->sex == 0) // get Default Avatar , according to sex
				return "assets/images/avatarF.png";
			else
				return "assets/images/avatarM.png";
		}
		// avatarPath is NOT NULL
		$path = $this->serverPathDownload . $user->user_id . "/" . $user->avatarPath;
	// $path = $this->Service->constructUrl('asset.images'.$user->user_id . $user->avatarPath ) ;
	//	echo "PATH : " . $this->getAsset('subsub.jpg') ;
		return $path;	
	}
}
?>